﻿using Core.Framework.Model.Common;
using Microsoft.EntityFrameworkCore;

namespace Core.DataAccess.Model.Project.AppInfo
{
    public partial class ProjectAppInfoContext : DbContext
    {
        public ProjectAppInfoContext()
        {
        }

        public ProjectAppInfoContext(DbContextOptions<ProjectAppInfoContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Custom> Custom { get; set; }
        public virtual DbSet<CustomAttrs> CustomAttrs { get; set; }
        public virtual DbSet<CustomType> CustomType { get; set; }
        public virtual DbSet<CustomUser> CustomUser { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(CoreStartupHelper.GetConnectionValue("AppInfo_SqlServerConnection"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Custom>(entity =>
            {
                entity.ToTable("custom");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Sort).HasColumnName("sort");

                entity.Property(e => e.Tag)
                    .HasColumnName("tag")
                    .HasMaxLength(10)
                    .IsUnicode(false);

                entity.Property(e => e.Type).HasColumnName("type");
            });

            modelBuilder.Entity<CustomAttrs>(entity =>
            {
                entity.ToTable("custom_attrs");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Sort).HasColumnName("sort");

                entity.Property(e => e.Tag)
                    .HasColumnName("tag")
                    .HasMaxLength(10)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<CustomType>(entity =>
            {
                entity.ToTable("custom_type");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.ProjectToken)
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(15)
                    .IsUnicode(false);

                entity.Property(e => e.UpKey).HasColumnName("up_key");
            });

            modelBuilder.Entity<CustomUser>(entity =>
            {
                entity.ToTable("custom_user");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.Sort).HasColumnName("sort");

                entity.Property(e => e.Tag)
                    .HasColumnName("tag")
                    .HasMaxLength(10)
                    .IsUnicode(false);

                entity.Property(e => e.Type).HasColumnName("type");
            });
        }
    }
}
